package com.example.lucene.dao;

import com.example.lucene.model.KnowledgeBase;
import com.example.lucene.model.ProductCategory;
import org.apache.ibatis.session.SqlSession;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.sql.Timestamp;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @Author yanggld
 * @Date 2019/5/24-16:31
 * @Description
 */
@Component
public class knowledgeBaseDao {

	@Autowired
	private SqlSession sqlSession;

	public List<ProductCategory> getIndexProduct() {
		return sqlSession.selectList("escloud.knowledgebasemapper.selectIndexProduct");
	}

	public List<KnowledgeBase> getKnowledgeBase(String productCode, String mode, Timestamp effectTime) {
		Map<String, String> map = new HashMap<String, String>();
		map.put("productCode", productCode);
		map.put("mode", mode);
		map.put("effectTime", effectTime.toString());
		return sqlSession.selectList("escloud.knowledgebasemapper.selectKnowledgeBaseListByProduct", map);

	}

	public void validKnowledgeBase(List<KnowledgeBase> kbs) {
		List<Long> ids = new ArrayList<>();
		for (KnowledgeBase kb : kbs) {
			ids.add(kb.getKnowledgeBaseId());
		}
		Map<String, List<Long>> map = new HashMap<>();
		map.put("ids", ids);
		sqlSession.update("escloud.knowledgebasemapper.validKnowledgeBaseByList", map);
	}
}
